import { RouteItemType } from "@/routers/interface/index.ts";

/**
 * @description 菜单扁平化，将多维数组扁平化为一维数组，一般用于动态添加路由
 * @param {Array} menuList 菜单列表，一般指用户的菜单权限
 * @returns {Array} 扁平化后的菜单列表
 */
export function getFlatMenuList(menuList: RouteItemType[]): RouteItemType[] {
  let copyMenuList: RouteItemType[] = JSON.parse(JSON.stringify(menuList));

  let result = copyMenuList.flatMap((item) => {
    if (item.children) return [item, ...getFlatMenuList(item.children)];
    else return [item];
  });
  return result;
}
export function getToken() {
  return sessionStorage.getItem("token");
}
